// src/utils/locale.ts
import { ref } from 'vue'
import type { Language } from 'element-plus'

// 定义可用的语言类型
type AvailableLanguage = 'zh-cn' | 'en'

// 当前语言状态 - 默认中文
const currentLanguage = ref<AvailableLanguage>('zh-cn')

// 语言映射
const languageMap: Record<AvailableLanguage, () => Promise<Language>> = {
  'zh-cn': () => import('element-plus/dist/locale/zh-cn.mjs'),
  'en': () => import('element-plus/dist/locale/en.mjs')
}

// 获取当前语言配置
const getElementPlusLocale = async (): Promise<Language> => {
  const module = await languageMap[currentLanguage.value]()
  return module.default
}

// 切换语言
const changeLanguage = (lang: AvailableLanguage) => {
  currentLanguage.value = lang
}

export {
  currentLanguage,
  getElementPlusLocale,
  changeLanguage,
  type AvailableLanguage
}
